import threading
from random import randint
import time
from queue import Queue
class pro_and_con_num:
    def __init__(self):
        self.product=Queue()
    def produce(self):
        """
        用于随机生成0-100的整数
        :return:
        """
        while True:
            pro_num=randint(0,100)
            self.product.put(pro_num)
            print('product number:{}'.format(pro_num))
            time.sleep(1)
    def consume(self):
        """
        用于消耗整数
        :return:
        """
        while True:
            con_num=self.product.get()
            print('consume       product:{}'.format(con_num))
            time.sleep(2)
    def main(self):
        """
        分两个线程，分别消耗和生产
        :return:
        """
        t1=threading.Thread(target=self.produce)
        t2=threading.Thread(target=self.consume)
        t1.start()
        t2.start()
if __name__ == '__main__':
    func=pro_and_con_num()
    func.main()

